from django.db import models


class Admin(models.Model):
    username = models.CharField(verbose_name='用户名', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=64)

    def __str__(self):
        return self.username


class Department(models.Model):
    '''
    部门表
    '''
    title = models.CharField(verbose_name='标题', max_length=32)

    def __str__(self):
        '''
        需要定义这个方法，否则会返回一个对象，定义了此方法之后，会返回title
        :return:
        '''
        return self.title


class UserInfo(models.Model):
    '''
    员工表
    '''
    name = models.CharField(verbose_name='姓名', max_length=16)
    password = models.CharField(verbose_name='密码', max_length=64)
    age = models.IntegerField(verbose_name='年龄')
    account = models.DecimalField(verbose_name='账户余额', max_digits=10, decimal_places=2, default=0)
    creat_time = models.DateField(verbose_name='创建时间')
    # 年月日时分秒
    # creat_time = models.DateTimeField(verbose_name='创建时间')

    # 无约束
    # depart_id = models.BigIntegerField(verbose_name='部门id')

    # 有约束
    #   -to, 与那张表关联
    #   -to_field, 表中的那一列关联
    # 2.django自动
    #   -写的depart
    #   -生成数据列 depart_id
    # 3.关联表中的数据如果被删除
    # 3.1 级联删除
    depart = models.ForeignKey(to='Department', to_field='id', on_delete=models.CASCADE, verbose_name='部门')
    # 3.2 置空
    # depart = models.ForeignKey(to='Department', to_field='id', null=True, blank=True, on_delete=models.SET_NULL)

    # 在django中做的约束
    gender_choices = (
        (1, '男'),
        (2, '女')
    )
    gender = models.SmallIntegerField(verbose_name='性别', choices=gender_choices)


class PrettyNum(models.Model):
    '''
    靓号表
    '''
    mobile = models.CharField(verbose_name='手机号', max_length=32)
    price = models.DecimalField(verbose_name='价格', max_digits=10, decimal_places=2, default=0)
    level_choices = (
        (1, '1级'),
        (2, '2级'),
        (3, '3级'),
        (4, '4级'),
    )
    level = models.SmallIntegerField(verbose_name='级别', choices=level_choices, default=1)
    status_choices = (
        (1, '已占用'),
        (2, '未占用')
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choices, default=2)


class Task(models.Model):
    '''
    任务表
    '''
    level_choices = (
        (1, '晋级'),
        (2, '普通'),
        (3, '临时')
    )
    level = models.SmallIntegerField(verbose_name='级别', choices=level_choices, default=3)
    title = models.CharField(verbose_name='标题', max_length=64)
    detail = models.TextField(verbose_name='详细信息')
    user = models.ForeignKey(to=Admin, on_delete=models.CASCADE, verbose_name='负责人')


class Order(models.Model):
    oid = models.CharField(verbose_name='订单id', max_length=64)
    title = models.TextField(verbose_name='名称', max_length=32)
    price = models.CharField(verbose_name='价格', max_length=32)
    status_choices = (
        (1, '待支付'),
        (2, '已支付')
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choices, default=1)
    admin = models.ForeignKey(verbose_name='管理员', to=Admin, on_delete=models.CASCADE)
